define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                 shop_id:0,
                 editData:{},
                };
            },
            el: '#pageAddBook',
            created: function() {
                this.fetchData();
            },
              mounted: function() {
                    
                    if (this.mounted == 1) {
                        return;
                    }
                    
                this.mounted = 1;
            },

            methods: {
                fetchData: function() {
                    var _this = this;

                    this.shop_id = this.$route.params.shop_id;
                    this.id = this.$route.params.id;
                    if(this.id ){
                       this.getData();
                    }
                   
                   
                },
                getData:function(){
                  var that = this ;
                     that.loading = 1;
                     
                    app.get("mall/dining_table/find", {
                      shop_id :  this.shop_id,

                      id :  this.id
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      that.editData = res.data; 
                    });
                },
                
                saveBook:function(id){
                   var that = this;
                   if(that.loading==1){
                      return ;
                   }
                   this.loading=1;
                   var post ={};
                  $("#formNewBook").find("input").each(function(i,input){
                     post[$(input).attr('name')] = $(input).val();
                  });
                  
                  app.post("mall/dining_table/add",post,function(res){
                        that.loading=0;
                            if(res.code!=200){
                               app.alert(res.msg);
                               return ;
                            }
                           app.alert('保存成功');
                           app.setPageData("index",{reload:0});
                           that.$router.go(-1);
                    });
                },
                cancel:function(){
                   this.$router.go(-1);
                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
